import { fileURLToPath,pathToFileURL } from "url";
import fs from "fs"
 export const findAllControllerFiles=function(){
    let baseurl=new URL('..controllers',import.meta.url).href
    let basepath=fileURLToPath(baseurl)
    let allFiles=fs.readFileSync(basepath);
    let allControllerFiles = allFiles.filter(item=> item.endsWith('.js'))
    .map(item=> pathToFileURL(`${basepath}/${item}`).href)
    return allControllerFiles;

    
 }
 export const registryRoute =function (router,controlerFiles){
   controlerFiles.forEach(async file =>{
      let keyArr =item.split(' ');
      let reqMethod = keyArr[0];
            let reqPath = keyArr[1];
            let reqFn = obj[item];
            if (reqMethod === 'get') {
                router.get(reqPath, reqFn);
            }
            if (reqMethod === 'post') {
                router.post(reqPath, reqFn);
            }
            if (reqMethod === 'put') {
                router.put(reqPath, reqFn);
            }
            if (reqMethod === 'delete') {
                router.delete(reqPath, reqFn);
            }
   })
 }